import { Tween } from "cc"
import { PosBall } from "./PosBall"
import { App } from "../../App"
import { GameBaseModel } from "./GameBaseModel"
import { tween } from "cc"

/**
 * 玩家基类
 */
export class PlayBaseUser {
    /* 玩家所有球数组 */
    private _allBallList : number[]
    /* 玩家剩余球数组 */
    private _ballList : number[]
    /* 玩家地址 作为key值 */
    userAddress = ""
    /* 玩家昵称 */
    userNickname = ""
    /* 玩家身上金币数 */
    gold = 0
    /* 是否是房主 */
    isOwner = false
    /* 是否是自己 */
    mine = false
    /* 需要击打的球号 */
    hitBall = 0

    posBallCtrl : PosBall = null

    constructor() {
        this.init()
        this.reset()
    }

    init() {
        this.posBallCtrl = (App.Model.gameView as GameBaseModel).posBallCtrl
    }

    reset() {
        this._ballList = []
        this._allBallList = []
    }

    get allBallList() {
        return this._allBallList
    }

    set allBallList(value) {
        let value2 = value.sort((number1, number2)=>{ // 增序
            return number1 - number2
        })

        this._allBallList = value2
    }

    get ballList() {
        return this._ballList
    }

    set ballList(value) {
        let value2 = value.sort((number1, number2)=>{ // 增序
            return number1 - number2
        })

        this._ballList = value2
    }

    // 是否是属于我的球
    isBelognMine(ballNumber : number) {
        return this.allBallList.includes(ballNumber)
    }

    // 是否是房主
    getIsOwner() {
        return this.isOwner
    }

    // 移除球
    removeBall(ballNumber : number) {

        let isContain = this._ballList.includes(ballNumber)
        if(isContain) {
            this._ballList = this._ballList.filter(item=>{
                return item != ballNumber
            })
        }

    }

    // 摆杆击球
    onCue() {
        
    }

    // 摆母球
    posWhiteBall() {
    }

    getName() : String {
        return "NONE"
    }

}